package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.GoodsStatisticsBean;
import beans.TimeoutBean;

/**
 * Created by Administrator on 2018/8/14.
 */

public class StatisticsSortUtils {

    public static void sortStatisticsGoodsName(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsSupplier(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsSpecification(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsPurchase(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getPurchaseCount() - o1.getPurchaseCount() > 0) {
                        return 1;
                    } else if (o2.getPurchaseCount() - o1.getPurchaseCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getPurchaseCount() - o1.getPurchaseCount() < 0) {
                        return 1;
                    } else if (o2.getPurchaseCount() - o1.getPurchaseCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsUse(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getApplyCount() - o1.getApplyCount() > 0) {
                        return 1;
                    } else if (o2.getApplyCount() - o1.getApplyCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getApplyCount() - o1.getApplyCount() < 0) {
                        return 1;
                    } else if (o2.getApplyCount() - o1.getApplyCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsStock(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getStockCount() - o1.getStockCount() > 0) {
                        return 1;
                    } else if (o2.getStockCount() - o1.getStockCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getStockCount() - o1.getStockCount() < 0) {
                        return 1;
                    } else if (o2.getStockCount() - o1.getStockCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsReturn(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getReturnCount() - o1.getReturnCount() > 0) {
                        return 1;
                    } else if (o2.getReturnCount() - o1.getReturnCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getReturnCount() - o1.getReturnCount() < 0) {
                        return 1;
                    } else if (o2.getReturnCount() - o1.getReturnCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortStatisticsGoodsNoReturn(List<GoodsStatisticsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getNotReturnedCount() - o1.getNotReturnedCount() > 0) {
                        return 1;
                    } else if (o2.getNotReturnedCount() - o1.getNotReturnedCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<GoodsStatisticsBean.DataBean>() {
                @Override
                public int compare(GoodsStatisticsBean.DataBean o1, GoodsStatisticsBean.DataBean o2) {
                    if (o2.getNotReturnedCount() - o1.getNotReturnedCount() < 0) {
                        return 1;
                    } else if (o2.getNotReturnedCount() - o1.getNotReturnedCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

}
